易大师 11:15:45 (多人发送)
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <!-- <script>
    // [{pid: '', id: 1}, {pid: 1, id: 1.1}]   ===> [{pid: '', id: 1, children: [{pid: 1, id: 1.1}]}]
    let data = [{ pid: '', id: 1 }, { pid: 1, id: 1.1 }, { pid: 1, id: 1.2 }]
    let newData = tranListToTreeData(data, '')


    function tranListToTreeData(list, rootValue) {
      var arr = []
      list.forEach(item => {
        if (item.pid === rootValue) {
          debugger
          // 找到之后 就要去找 item 下面有没有子节点
          const children = tranListToTreeData(list, item.id)
          if (children.length) {
            // 如果children的长度大于0 说明找到了子节点
            item.children = children
          }
          arr.push(item) // 将内容加入到数组中
        }
      })
      return arr
    }
  </script> -->

  <script>
    let num = 0
    let sum = 0
    // function fn() {
    //   if (num < 5) {
    //     num++
    //     sum += num
    //     fn()
    //   }
    // }
    function fn() {
        num++
        sum += num
        console.log('aaaa');
      return num === 5 || fn()
    }
    fn()
    console.log(sum);
  </script>
</body>

</html>